package com.alex.wechat.mp.message.news.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.servlet.http.HttpServletRequest;

import org.jeecgframework.core.common.entity.IdEntity;
import org.jeecgframework.core.util.IpUtil;

/**
 * 图文消息模板项。
 * 
 * @author Debenson
 * @since 0.1
 */
@Entity
@Table(name = "wx_newsitem")
public class WxNewsItem extends IdEntity {
  private static final long serialVersionUID = 3129602078416573549L;

  private WxNewsTemplate newsTemplate;
  private String title;
  private String author;
  private String imagePath;
  private String content;
  private String description;
  private Integer orders;
  private String accountId;
  /** 外部链接 */
  private String url;
  /** 创建时间 */
  private Date createDate;
  /** 缩略图微信标识 */
  private String thumbMediaId;
  /** 缩略图微信url */
  private String thumbUrl;
  /** 文件存放的物理路径 */
  private String realPath;

  /**
   * 外部链接。
   * 
   * @return
   */
  @Column(name = "url", length = 128)
  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  @Column(name = "create_date")
  public Date getCreateDate() {
    return createDate;
  }

  public void setCreateDate(Date createDate) {
    this.createDate = createDate;
  }

  @Column(name = "accountid", length = 100)
  public String getAccountId() {
    return accountId;
  }

  public void setAccountId(String accountId) {
    this.accountId = accountId;
  }

  /**
   * 图文标题。
   * 
   * @return
   */
  @Column(name = "title")
  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  /**
   * 作者。
   * 
   * @return
   */
  @Column(name = "author")
  public String getAuthor() {
    return author;
  }

  public void setAuthor(String author) {
    this.author = author;
  }

  /**
   * 图片下载地址。
   * 
   * @return
   */
  @Column(name = "imagepath")
  public String getImagePath() {
    return imagePath;
  }

  public void setImagePath(String imagePath) {
    this.imagePath = imagePath;
  }

  /**
   * 图文消息的具体内容，支持HTML标签，必须少于2万字符，小于1M，且此处会去除JS, <br>
   * 涉及图片url必须来源"上传图文消息内的图片获取URL"接口获取。外部图片url将被过滤
   * 
   * @return
   */
  @Lob
  @Column(name = "content")
  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "templateid")
  public WxNewsTemplate getNewsTemplate() {
    return newsTemplate;
  }

  public void setNewsTemplate(WxNewsTemplate newsTemplate) {
    this.newsTemplate = newsTemplate;
  }

  /**
   * 图文消息的摘要，仅有单图文消息才有摘要，多图文此处为空
   * 
   * @return
   */
  @Column(name = "description")
  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  /**
   * 顺序。
   * 
   * @return
   */
  @Column(name = "orders")
  public Integer getOrders() {
    return orders;
  }

  public void setOrders(Integer orders) {
    this.orders = orders;
  }

  /**
   * 缩略图微信标识
   * 
   * @return
   */
  @Column(name = "THUMB_MEDIA_ID", length = 50)
  public String getThumbMediaId() {
    return thumbMediaId;
  }

  public void setThumbMediaId(String thumbMediaId) {
    this.thumbMediaId = thumbMediaId;
  }

  /** 文件存放的物理路径 */
  @Column(name = "REAL_PATH")
  public String getRealPath() {
    return realPath;
  }

  public void setRealPath(String realPath) {
    this.realPath = realPath;
  }

  /** 缩略图url */
  @Column(name = "THUMB_URL", length = 256)
  public String getThumbUrl() {
    return thumbUrl;
  }

  public void setThumbUrl(String thumbUrl) {
    this.thumbUrl = thumbUrl;
  }

  /**
   * 外部查看url
   * 
   * @param request
   * @return
   */
  public String viewUrl(HttpServletRequest request) {
    final String root = IpUtil.getWebRoot(request);
    String viewUrl = root + "/wxNewsItemController.do?goContent&id=" + getId();
    return viewUrl;
  }

}
